package com.lsqingfeng.springboot.config;

import com.lsqingfeng.springboot.service.UserService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

/**
 * @className: WebfluxRouter
 * @description:
 * @author: sh.Liu
 * @date: 2022-04-02 11:15
 */
@Configuration
public class WebfluxRouter {

    @Bean
    public RouterFunction<ServerResponse> route(UserService userService){
        return RouterFunctions
                .route(GET("/getUser")
                                .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
                        userService::getUser)
                .andRoute(GET("/delUser").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),userService::delUser)
                ;
    }

}
